package com.penjin.android.utils;


import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2016/3/24.
 */
public class DateUtil {

    private static SimpleDateFormat defaultDateFormat;
    private static SimpleDateFormat uiDateFormat;
    private static SimpleDateFormat chDateFormat;//中文日期格式
    static {
        defaultDateFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        uiDateFormat=new SimpleDateFormat("yyyy年MM月dd     hh:mm");
        chDateFormat=new SimpleDateFormat("yyyy年MM月dd日");
    }

    public static String getBetweenDays(String startDate, String endDate) throws Exception {
        Date start = defaultDateFormat.parse(startDate);
        Date end = defaultDateFormat.parse(endDate);
        long l = end.getTime() - start.getTime();
        long day = l / (24 * 60 * 60 * 1000);
        long hour = (l / (60 * 60 * 1000) - day * 24);
        double dou=(double)hour/24d;
        return "共计"+day+"."+(int)dou*10+"天";
    }

    public static String toUIDate(String dateStr) throws  Exception{
        Date date=defaultDateFormat.parse(dateStr);
        return uiDateFormat.format(date);
    }

    public static boolean isEndDateValid(String startDateStr,String endDateStr){
        try {
            Date startDate=chDateFormat.parse(startDateStr);
            Date endDate=chDateFormat.parse(endDateStr);
            return startDate.before(endDate);
        }catch (Exception e){
            return false;
        }
    }
}
